# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=terminado
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}"  "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.8.2
pkgrel=2
pkgdesc="Terminals served to term.js using Tornado websockets (mingw-w64)"
arch=('any')
url='https://github.com/takluyver/terminado'
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-python3-tornado"
         "${MINGW_PACKAGE_PREFIX}-python2-tornado"
         "${MINGW_PACKAGE_PREFIX}-python3-ptyprocess"
         "${MINGW_PACKAGE_PREFIX}-python2-ptyprocess")
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
source=("${_realname}-${pkgver}.tar.gz::https://files.pythonhosted.org/packages/source/t/terminado/terminado-${pkgver}.tar.gz")
sha256sums=('de08e141f83c3a0798b050ecb097ab6259c3f0331b2f7b7750c9075ced2c20c2')

prepare() {
  for pver in {2,3}; do
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_realname}-${pkgver}" "python${pver}-build-${CARCH}"
  done

}

build() {
  for pver in {2,3}; do
    msg "Python ${pver} build for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done
}

#check() {
#  for pver in {2,3}; do
#    msg "Python ${pver} test for ${CARCH}"
#    cd "${srcdir}/python${pver}-build-${CARCH}"
#    ${MINGW_PREFIX}/bin/python${pver} setup.py check
#  done
#}

package_python3-terminado() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3"
           "${MINGW_PACKAGE_PREFIX}-python3-tornado"
           "${MINGW_PACKAGE_PREFIX}-python3-ptyprocess")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -D -m644 "LICENSE" ${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE
}

package_python2-terminado() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2"
           "${MINGW_PACKAGE_PREFIX}-python2-tornado"
           "${MINGW_PACKAGE_PREFIX}-python2-ptyprocess")

  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -D -m644 "LICENSE" ${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE
}

package_mingw-w64-i686-python2-terminado() {
  package_python2-terminado
}

package_mingw-w64-i686-python3-terminado() {
  package_python3-terminado
}

package_mingw-w64-x86_64-python2-terminado() {
  package_python2-terminado
}

package_mingw-w64-x86_64-python3-terminado() {
  package_python3-terminado
}
